import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import leastsq
import pylab as pl

X = np.array([0.0,199.6,322.4,421.3,522.4,573.3,622.8,672.0,716.7,733.9,791.6,890.9,980.3])
Y = np.array([0.0,30,55,100,130,160,195,240,280.25,320.03,400.99,500.68,650.97])
Y1 = np.array([0.0,40,70,110,160,190,250,270,320.25,350.03,480.99,590.68,750.97])


#X1 = np.array([0.0,])
#Y2 = np.array()

func = np.polyfit(X,Y,3)

pl = np.poly1d(func)

_x = np.arange(0,1000)
#_y = np.array([func for x in _x])

#plt.plot(X,Y,'ro',_x,_y,'b',linewidth=2)
plt.plot(X,Y,'ro')

print func
print pl


_Y = np.array([ (2e-01)*x + (1e-05)*x**2 + (7e-07)*x**3 for x in _x])

_Y1 = np.array([ (3e-01)*x + (2e-05)*x**2 + (8e-07)*x**3 for x in _x])

_Y2 = np.array([ (4e-01)*x + (3e-05)*x**2 + (9e-07)*x**3 for x in _x])

#
plt.plot( _x, _Y,'b',linewidth=2)

plt.plot( _x, _Y1,'b',linewidth=2)

plt.plot( _x, _Y2,'b',linewidth=2)

#5.996e-07 x - 1.106e-05 x + 0.1009 x + 2.31

plt.plot(_x,pl(_x),'b')
plt.title("y = {} + {}x + {}x^2 + {}x^3$".format(pl[3],pl[2],pl[1],pl[0]))
plt.annotate('S-Q', xy=(716.7,280.25), xytext=(200, 480), arrowprops=dict(facecolor='black', shrink=0.05),)

plt.show()


